﻿/*
 * Copyright 2009, Payton Byrd
 * Licensed Under the Microsoft Public License (MS-PL)
 */

using PaytonByrd.Extensions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Data;

namespace PaytonByrd.Extensions.UnitTests
{
    
    
    /// <summary>
    ///This is a test class for CollectionExtensionsTest and is intended
    ///to contain all CollectionExtensionsTest Unit Tests
    ///</summary>
    [TestClass()]
    public class CollectionExtensionsTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for FirstRow
        ///</summary>
        public void DataTableFirstRowTestHelper<T>()
            where T : DataRow
        {
            DataTable table = new DataTable();
            table.Columns.Add(new DataColumn("Test", typeof(string)));
            T expected = (T)table.NewRow();
            expected["Test"] = "Test Value";
            table.Rows.Add(expected);
            T anotherRow = (T)table.NewRow();
            table.Rows.Add(anotherRow);

            T actual;
            actual = table.FirstRow<T>();
            Assert.AreEqual(expected, actual);
            Assert.AreEqual(expected["Test"], actual["Test"]);
        }

        [TestMethod()]
        public void DataTableFirstRowTest()
        {
            DataTableFirstRowTestHelper<DataRow>();
        }

        /// <summary>
        ///A test for FirstItem
        ///</summary>
        public void FirstItemGenericListTestHelper<T>()
        {
            List<T> collection = new List<T>(); 
            T expected = default(T); 
            T actual;
            actual = collection.FirstItem();
            Assert.AreEqual(expected, actual);
        }

        [TestMethod()]
        public void FirstItemGenericListTest()
        {
            FirstItemGenericListTestHelper<GenericParameterHelper>();
        }

        /// <summary>
        ///A test for FirstItem
        ///</summary>
        [TestMethod()]
        public void FirstItemArrayTest()
        {
            Array array = new string[2]; 
            array.SetValue("Test Value", 0);
            array.SetValue(null, 0);
            object expected = array.GetValue(1); 
            object actual;
            actual = array.FirstItem();
            Assert.AreEqual(expected, actual);
        }
    }
}
